#include <iostream>
#include <cstring>
using namespace std;

int a[100005], n, maxx;
bool c[100005];
int lb[100005], lr[100005], in1, in2;

void func(){
    int sum=0;
    for (int i = 0; i < n; i++){
        if(c[i]){
            if (in2 && a[lr[in2-1]] == a[i]){
                sum += a[i];
            }
            lr[in2++] = i;
        } else {
            if (in1 && a[lb[in1-1]] == a[i]){
                sum += a[i];
            }
            lb[in1++] = i;
        }
    }
    maxx = max (maxx, sum);
}

void dfs(int d){
    if (d == n){
        in1 = in2 = 0;
        memset(lb, 0, sizeof lb);
        memset(lr, 0, sizeof lr);
        func();
        return;
    }
    c[d] = 1;
    dfs(d + 1);
    c[d] = 0;
    dfs(d + 1);
}

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--){
        maxx=0;
        cin >> n;
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        dfs(0);
        cout << maxx << '\n';
    }
    return 0;
}
